function createAssigner(keyFunc, undefinedOnly) {
  return function (targetObj) {
    if (arguments.length < 2) return targetObj;
    var lengths = arguments.length;
    for (var i = 1; i < lengths; ++i) {
      var source = arguments[i];
      var keys = keyFunc(source);
      for (var j = 0; j < keys.length; ++j) {
        var key = keys[j];
        if (!undefinedOnly || targetObj[key] === void 0) {
          targetObj[key] = source[key];
        }
      }
    }
    return targetObj;
  };
}

module.exports = createAssigner;
